<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get_detail';
if($_RQ['op']=='get_detail'){
	$return['shopset']=plugin('jy_weishop')->plugin_setting('shopset');
	$return=model('jy_weishop/goods_item')->get_goodsitem($return);
	$return['goods']['api_data']=json_decode($return['goods']['api_data'],true);
	if($_RQ['fromuser']){
		model('jy_weishop/fenxiao')->up_fenfee($return['shopset'],$return['goods']);
	}
	if(strpos($return['goods']['no_de_sales'],'no_member_discount')===false && $return['setting']['no_vipshow']!=1){
		$return['nextlevel']=model('jy_weishop/member')->get_nextlevel(0,true);
	}
	if($return['nextlevel']['id']){
		$vipprice=model('jy_weishop/goods')->get_diyprice($return['goods'],$return['nextlevel']);
		if($vipprice>=$return['goods']['price']){
			$return['nextlevel']=array();
		}else{
			$return['goods']['vipprice']=$vipprice;
		}
	}
	$return['sharedata']['link']=custom_url('jy_mcaigou/goods.detail//id='.$return['goods']['id'].'&fromuser='.$_SESSION['uid'].'&onemerchid='.$_SESSION['onemerchid'],true);
	$keywords=$return['goods']['share_keywords']?:$return['goods']['title'].','.$return['sharedata']['desc'];
	$desc=$return['sharedata']['desc'];
	set_html('title',$return['goods']['title']?$return['goods']['title'].'-'.$return['shopset']['title']:'商品详情');
	set_html('keywords',$keywords);
	set_html('description',$desc);
	exi($return);
}
if($_RQ['op']=='check_buy'){
	$goodsid=$_RQ['goodsid']?intval($_RQ['goodsid']):$_SESSION['goodsid'];
	if(!$goodsid){
		exi('请选择商品！','error');
	}
	$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid),array('id','title','no_onebuy'));
	if($goods['no_onebuy']){
		exi('该商品，不能单独购买！','error');
	}
	model('jy_weishop/activity/sales')->check_sale_new(array(array('goodsid'=>$goodsid)));
	model('jy_weishop/goods')->check_buy($goodsid,$_RQ['num'],$_RQ['optionsid']);
	exi('','','jy_mcaigou/order.create//goodsid='.$goodsid.'&num='.$_RQ['num'].'&optionsid='.$_RQ['optionsid'].'&addressid='.$_RQ['addressid'].'&storeid='.$_RQ['storeid'].'&roomid='.$_RQ['roomid']);
}